<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 759px;
            /* height: 300px; */
            margin: 0 auto;
            display: flex;
            flex-wrap: wrap;
            align-content: flex-start;
            align-items: flex-start;
            border: 1px solid black;
        }

        .box div {
            width: 150px;
            height: 150px;
            line-height: 150px;
            text-align: center;
            border: 1px solid rgb(231, 119, 119);
        }

        .active {
            background-color: rgb(215, 160, 57);
        }
    </style>
</head>

<body>
    <button>开始</button>
    <div class="box">

    </div>
    <script>
        let box = document.querySelector(".box")
        let btn = document.querySelector("button")
        // let x = 12
        // console.log(div);
        for (let i = 1; i <= 15; i++) {
            let div = document.createElement("div")
            div.innerHTML = i
            box.appendChild(div)
        }
        function act() {
            let div = document.querySelectorAll(".box div")
            let num = Math.floor(Math.random() * 15)
            if (document.querySelector(".active")) {
                document.querySelector(".active").className = ""
            }
            div[num].classList.add("active")
        }
        // btn.onclick = function () {
        //     let a = setInterval(act, 90)
        //     this.innerHTML = "停止";
        //     this.onclick = function () {
        //         clearInterval(a)
        //         this.innerHTML = "开始";
        //     }
        // }
        let flag = true;
        let a;
        btn.addEventListener('click', function () {
            if (flag) {
                a = setInterval(act, 90)
                this.innerHTML = "停止";
                flag = false;
                // return flag;
            } else {
                this.innerHTML = "开始";
                clearInterval(a)
                flag = true;
                // return flag;
            }
        }
        )
        // console.log(flag);
        



    </script>
</body>

</html>